package com.example.recyclerviewtest.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.recyclerviewtest.MainActivity;
import com.example.recyclerviewtest.R;
import com.example.recyclerviewtest.bean.Infos;

import java.util.ArrayList;
import java.util.List;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
    private Context content;
    private Infos info =null;
    private List<Infos> lists =new ArrayList<Infos>();
    public  MyAdapter(Context content){
        this.content =content;
    }
    public void setData(List<Infos> data){
        this.lists =data;
    }
    public void addData(Infos info){
        lists.add(info);
    }
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view =View.inflate(content,R.layout.recjycler_item,null);
        MyViewHolder holder =new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        info =lists.get(position);
        holder.item_title.setText(info.getTitle());
        holder.item_author.setText(info.getAuthor());
        holder.item_love.setText(info.getLove()+"");

    }

    @Override
    public int getItemCount() {
        return lists.size();
    }




    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView item_title,item_author,item_love;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            item_author =itemView.findViewById(R.id.item_author);
            item_love =itemView.findViewById(R.id.item_love);
            item_title =itemView.findViewById(R.id.item_title);
        }
    }
}
